package org.example.thread;

import lombok.SneakyThrows;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutureManager {
    public String execute() throws Exception{
        ExecutorService executor = Executors.newFixedThreadPool(1);
        Future<String> future = executor.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("业务逻辑");
                return "result";
            }
        });
        // 这里需要返回值时会阻塞主线程
        String result = future.get();
        System.out.println(result);
        return result;
    }

    public static void main(String[] args) throws Exception {
        FutureManager manager = new FutureManager();
        manager.execute();
    }
}
